package com.mrjy.maintain.bo;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.mrjy.common.entity.NewsInfo;
import com.mrjy.common.entity.UserInfo;
import com.mrjy.common.util.DateUtil;
import com.mrjy.maintain.dao.INewsInfoDao;

@Service("NewsInfoBo")
public class NewsInfoBo implements INewsInfoBo {
	@Resource
	private INewsInfoDao newsInfoDao;



	@Override
	public Map<String, Object> queryPageNewsInfo(NewsInfo NewsInfo,UserInfo userInfo) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("total", newsInfoDao.countNewsInfo(NewsInfo));
		List<NewsInfo> list = newsInfoDao.queryPageNewsInfo(NewsInfo);	
		map.put("rows",list);
		return map;
	}
	
	@Override
	public Object queryNewsTypeList(){
		return newsInfoDao.queryNewsTypeList();	
	}
	

	@Override
	public int insert(NewsInfo newsInfo) {
		// TODO Auto-generated method stub
		newsInfo.setPublishDate(DateUtil.dateToString(new Date(), 2));
		return newsInfoDao.insert(newsInfo);
	}

	@Override
	public NewsInfo queryById(int id) {
		// TODO Auto-generated method stub
		return newsInfoDao.queryById(id);
	}

	@Override
	public int updateById(NewsInfo newsInfo) {
		// TODO Auto-generated method stub
		return newsInfoDao.updateById(newsInfo);
	}

	@Override
	public int deleteByIds(int[] ids) {
		// TODO Auto-generated method stub
		try{
			return newsInfoDao.deleteByIds(ids);
		}catch(DataAccessException  e){
			return 0;
		}
	}

	@Override
	public int updateDisableFlag(NewsInfo NewsInfo) {
		// TODO Auto-generated method stub
		return newsInfoDao.updateDisableFlag(NewsInfo);
	}

}
